/**
 * 
 */
package com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.usersaction;

import java.util.ArrayList;

import com.alstudio.module.xmpp.protocol.xmpp.packact.ALXmppDomainConfig;
import com.alstudio.module.xmpp.protocol.xmpp.packact.IQNameSpace;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.AlXmlTag;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate;
import com.alstudio.pojo.module.user.User;

/**
 * 将用户加入黑名单
 * 
 * @author alonso lee
 * 
 */
public class AddUserToBlackListIQCreator extends BaseIQTemplate {

	private ArrayList<User> users;

	public AddUserToBlackListIQCreator(ArrayList<User> users, String domain) {
		// TODO Auto-generated constructor stub
		this.domain = domain;
		this.users = users;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate
	 * #getIQXml()
	 */
	@Override
	public String getIQXml() {
		// TODO Auto-generated method stub

		mALIQCreator.setType(IQ_TYPE_SET);
		mALIQCreator.setNs(IQNameSpace.NS_BLACK_LIST);
		to = ALXmppDomainConfig.getALXmppDomainConfig().getDomainByNameSpace(
				mALIQCreator.getNs());
		mALIQCreator.setTo(to + domain);

		AlXmlTag tag = new AlXmlTag("list");
		tag.setHasSubTag(true);
		tag.setAtt("name", "blacklist");
		tagList.add(tag);

		for (User u : users) {
			tag = new AlXmlTag("item");
			tag.setAtt("type", "jid");
			tag.setAtt("value", u.getJid());
			tag.setAtt("action", "deny");
			tag.setAtt("order", u.getBareJid());
			tagList.add(tag);
		}

		String xml = "";
		try {
			xml = mALIQCreator.getXml();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return xml;
	}

}
